package org.stan.beanvalidator.factory.validator;

import org.stan.beanvalidator.annotation.BeanValidate;
import org.stan.beanvalidator.bean.PatternField;
import org.stan.beanvalidator.factory.AnnotationFactoty;
import org.stan.beanvalidator.utils.ValidatorUtil;
import java.lang.reflect.Field;
import java.util.Set;

/**
 * @ClassName DefaultValidator 默认校验器
 * 除去自定义注解校验的字段都会进来
 * @Author src
 * @Date 2020-06-13 15:18
 * @Discriptions
 */
public class DefaultValidator extends AnnotationFactoty {
    @Override
    public void beanValidate(Field field, Object bean) throws Exception {

    }

    @Override
    public void beanValidate(Field field, Object bean, Set<String> excludes) throws Exception {

    }

    /**
     *@Description 原本没有添加自定义注解，在这里可以动态校验
     *@Author src
     *@Date 2020-06-13 15:21
     *@Param
     *@return
     */
    @Override
    public void beanValidate(Object bean, Field field, Set<PatternField> patternFields) throws Exception {
        // 按新的格式校验
        ValidatorUtil.validateNew(field, bean, patternFields);
    }

    @Override
    public void beanValidate(Field field, Object bean, Class<?> clazz, BeanValidate beanValidate) throws Exception {
        // 按新的格式校验
        ValidatorUtil.validateAnnotation(beanValidate,field,bean,clazz);
    }
}
